package com.java.model;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class UserSession
    implements HttpSessionBindingListener
{
    
    /**
     * 사용자 세션정보를 설정
     * 
     * @param map
     */
    public UserSession( Map map )
    {
        super();
        this.user_id        = (String) map.get( "user_id" );                                //통합ID
        this.user_name      = (String) map.get( "user_name" );                   //사용자이름
        this.login_id       = (String) map.get( "login_id" );                              //로그인ID
        this.group_id       = (String) map.get( "group_id" );                          //권한ID
        this.group_name     = (String) map.get( "group_name" );              //권한명
        this.login_pwd      = (String) map.get( "login_pwd" );                      //로그인PWD
        this.email_address  = (String) map.get( "email_address" );             //이메일주소
        this.mobile         = (String) map.get( "mobile" );                                  //핸드폰번호
        this.phone          = (String) map.get( "phone" );                                   //전화번호
        this.company_name   = (String) map.get( "company_name" );      //회사이름
        this.address1       = (String) map.get( "address1" );                              //기본주소
        this.address2       = (String) map.get( "address2" );                             //상세주소
        this.zipcode        = (String) map.get( "zipcode" );                                 //ZIP코드
        this.login_fail_cnt = (String) map.get( "login_fail_cnt" );                  //로그인 실패 횟수
        this.active         = (String) map.get( "active" );                                        //
        this.repl_user_id   = (String) map.get( "login_id" );                              //수정자ID
        this.conn_group = (String) map.get( "conn_group");                         //권한그룹별 접속 도메인 구분자
                                                                                                                                     //0:운영자, 1:학습자, 2:CP, 3:기업운영자, 4:강사
    }

    /**
     * 사용자 세션정보를 설정
     * 
     * @param map
     */
public void setUserSession( Map map )
    {
        if ( map.containsKey( "user_id" ) )
        {
            this.user_id = (String) map.get( "user_id" );
        }
        if ( map.containsKey( "user_name" ) )
        {
            this.user_name = (String) map.get( "user_name" );
        }
        if ( map.containsKey( "group_id" ) )
        {
            this.group_id = (String) map.get( "group_id" );
        }
        if ( map.containsKey( "group_name" ) )
        {
            this.group_name = (String) map.get( "group_name" );
        }
        if ( map.containsKey( "login_id" ) )
        {
            this.login_id     = (String) map.get( "login_id" );
            this.repl_user_id = (String) map.get( "login_id" );
        }
        if ( map.containsKey( "login_pwd" ) )
        {
            this.login_pwd = (String) map.get( "login_pwd" );
        }
        if ( map.containsKey( "email_address" ) )
        {
            this.email_address = (String) map.get( "email_address" );
        }
        if ( map.containsKey( "mobile" ) )
        {
            this.mobile = (String) map.get( "mobile" );
        }
        if ( map.containsKey( "phone" ) )
        {
            this.phone = (String) map.get( "phone" );
        }
        if ( map.containsKey( "company_name" ) )
        {
            this.company_name = (String) map.get( "company_name" );
        }
        if ( map.containsKey( "address1" ) )
        {
            this.address1 = (String) map.get( "address1" );
        }
        if ( map.containsKey( "address2" ) )
        {
            this.address2 = (String) map.get( "address2" );
        }
        if ( map.containsKey( "zipcode" ) )
        {
            this.zipcode = (String) map.get( "zipcode" );
        }
        if ( map.containsKey( "login_fail_cnt" ) )
        {
            this.login_fail_cnt = (String) map.get( "login_fail_cnt" );
        }
        if ( map.containsKey( "active" ) )
        {
            this.active = (String) map.get( "active" );
        }
        if ( map.containsKey( "conn_group" ) )
        {
            this.conn_group = (String) map.get( "conn_group" );
        }
    }

    /**
     * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
     */
    public void valueBound( HttpSessionBindingEvent event )
    {
        // ApplicationSessionManager.plusCurrentCount();
    }

    /**
     * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
     */
    public void valueUnbound( HttpSessionBindingEvent event )
    {
        // ApplicationSessionManager.minusCurrentCount();
    }

    private String user_id;
    private String user_name;
    private String group_id;
    private String group_name;
    private String login_id;
    private String login_pwd;
    private String email_address;
    private String mobile;
    private String phone;
    private String company_name;
    private String address1;
    private String address2;
    private String zipcode;
    private String login_fail_cnt;
    private String active;
    private String repl_user_id;
    private String conn_group;


    public String toString()
    {
        ToStringBuilder ret = new ToStringBuilder( this, ToStringStyle.MULTI_LINE_STYLE );
        ret.append( "user_id: " ).append( user_id );
        ret.append( "user_name: " ).append( user_name );
        ret.append( "group_id: " ).append( group_id );
        ret.append( "group_name: " ).append( group_name );
        ret.append( "login_id: " ).append( login_id );
        ret.append( "login_pwd: " ).append( login_pwd );
        ret.append( "email_address: " ).append( email_address );
        ret.append( "mobile: " ).append( mobile );
        ret.append( "phone: " ).append( phone );
        ret.append( "company_name: " ).append( company_name );
        ret.append( "address1: " ).append( address1 );
        ret.append( "address2: " ).append( address2 );
        ret.append( "zipcode: " ).append( zipcode );
        ret.append( "login_fail_cnt: " ).append( login_fail_cnt );
        ret.append( "active: " ).append( active );
        ret.append( "conn_group: " ).append( conn_group );
        return ret.toString();
    }

    public String getUser_id()
    {
        return user_id;
    }

    public void setUser_id( String user_id )
    {
        this.user_id = user_id;
    }

    public String getUser_name()
    {
        return user_name;
    }

    public void setUser_name( String user_name )
    {
        this.user_name = user_name;
    }

    public String getGroup_id()
    {
        return group_id;
    }
    
    public void setGroup_id( String group_id )
    {
        this.group_id = group_id;
    }

    public String getGroup_name()
    {
        return group_name;
    }

    public void setGroup_name( String group_name )
    {
        this.group_name = group_name;
    }
    
    public String getLogin_id()
    {
        return login_id;
    }

    public void setLogin_id( String login_id )
    {
        this.login_id = login_id;
    }

    public String getLogin_pwd()
    {
        return login_pwd;
    }

    public void setLogin_pwd( String login_pwd )
    {
        this.login_pwd = login_pwd;
    }

    public String getEmail_address()
    {
        return email_address;
    }

    public void setEmail_address( String email_address )
    {
        this.email_address = email_address;
    }

    public String getMobile()
    {
        return mobile;
    }

    public void setMobile( String mobile )
    {
        this.mobile = mobile;
    }

    public String getPhone()
    {
        return phone;
    }

    public void setPhone( String phone )
    {
        this.phone = phone;
    }

    public String getCompany_name()
    {
        return company_name;
    }

    public void setCompany_name( String company_name )
    {
        this.company_name = company_name;
    }

    public String getAddress1()
    {
        return address1;
    }

    public void setAddress1( String address1 )
    {
        this.address1 = address1;
    }

    public String getAddress2()
    {
        return address2;
    }

    public void setAddress2( String address2 )
    {
        this.address2 = address2;
    }

    public String getZipcode()
    {
        return zipcode;
    }

    public void setZipcode( String zipcode )
    {
        this.zipcode = zipcode;
    }

    public String getLogin_fail_cnt()
    {
        return login_fail_cnt;
    }

    public void setLogin_fail_cnt( String login_fail_cnt )
    {
        this.login_fail_cnt = login_fail_cnt;
    }

    public String getActive()
    {
        return active;
    }

    public void setActive( String active )
    {
        this.active = active;
    }
    public void setReplUsrId( String repl_user_id )
    {
        this.repl_user_id = repl_user_id;
    }
    
    public String getReplUsrId()
    {
        return repl_user_id;
    }
    
    public void setConnGroup(String conn_group)
    {
        this.conn_group = conn_group;
    }

    public String getConnGroup( )
    {
       return conn_group;
    }
}
